package com.community.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.community.entity.User;
import com.community.service.IUserService;

@Controller
@RequestMapping("/user")
public class UserRegisterController {

	@Autowired
	private IUserService IUserService;
	
	@RequestMapping("/register")
	public String userRegister(){
		return "/user/register";
	}
	
	@RequestMapping("/register/submit")
	@ResponseBody
	public int userRegisterSubmit(String phone,String pwd,HttpSession session){
		
		User u = new User();
		u.setCount(phone);
		u.setPassword(pwd);
		u.setHeadPath("/assets/images/tab_user@3x.png");//设置默认头像
		IUserService.addUser(u);
		return 1;
	}
	
	@RequestMapping("/checkPhoneIsExist")
	@ResponseBody
	public int checkPhoneIsExist(String phone){
		
		User u = IUserService.getUserByCount(phone);
		if(u == null){
			return 1;
		}else{
			return 0;
		}
		
		
	}
}
